<!--
 * @Author: firesky
 * @Date: 2020-08-31 09:49:57
 * @LastEditTime: 2021-04-06 15:11:42
 * @LastEditors: firesky
-->
<template>
  <div class="app-container">
    <div>
      <el-row class="admin-top-g">
        <GButton
          :is-add-show="!!(limits.length >=1 && limits.filter(it => it.FName === '新增').length)"
          :is-edit-show="!!(limits.length >=1 && limits.filter(it => it.FName === '修改').length)"
          :is-del-show="!!(limits.length >=1 && limits.filter(it => it.FName === '删除').length)"
          :lists="options"
          @onAdd="addUser"
          @onEdit="editUser"
          @onDelete="delUser"
          @selectSettings="selectSettings"
        />

      </el-row>
      <br>

      <el-row class="common-row" style="margin-top: -20px;">
        <template v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length">
          <el-date-picker
            v-model="gapTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="selectGapTime" />
          <el-input v-model="keyword" clearable style="width: 160px;" placeholder="请输入关键字" @keyup.native.enter="searchUser" @change="searchUser"/>
          <el-select v-model="fdeleted" filterable clearable style="width: 160px;" placeholder="请选择在职状态" @change="searchUser">
            <el-option
              v-for="item in fdeletedList"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-select v-model="fdeptname" filterable clearable style="width: 160px;" placeholder="请选择部门" @change="searchUser">
            <el-option
              v-for="item in bmList"
              :key="item.finterid"
              :label="item.fname"
              :value="item.fname"/>
          </el-select>
          <el-select v-model="fcompany" clearable filterabl style="width: 160px;" placeholder="请选择公司" @change="searchUser">
            <el-option
              v-for="item in gsList"
              :key="item.finterid"
              :label="item.fname"
              :value="item.fname"/>
          </el-select>
          <el-button type="primary" icon="el-icon-search" @click="searchUser">搜索</el-button>
        </template>
        <!--<el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '新增').length" type="success" icon="el-icon-plus" @click="addUser">添加</el-button>
        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '修改').length" type="success" icon="el-icon-edit" @click="editUser">编辑</el-button>
        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '删除').length" type="success" icon="el-icon-delete" @click="delPlUser">删除</el-button>
         -->

        <!-- 上传文件 -->
        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '导出').length" type="success" icon="el-icon-download" @click="downData">导出</el-button>
        <el-upload
          v-if="limits.length >=1 && limits.filter(it => it.FName === '导入').length"
          ref="upload"
          :on-preview="handlePreview"
          :on-remove="handleRemove"
          :file-list="fileList"
          :limit="1"
          :data="upData"
          :on-exceed="exceed"
          :on-success = "notice"
          :before-upload="beforeAvatarUpload"
          :auto-upload="false"
          style="display: inline-block;"
          class="upload-demo"
          action="/excel/zyImport">
          <el-button slot="trigger" style="margin-left: 10px;" size="small" icon="el-icon-upload" type="warning">上传xlsx文件</el-button>
          <el-button size="small" type="warning" icon="el-icon-circle-check" @click="submitUpload">提交</el-button>

        </el-upload>

        <!-- <el-button type="danger" >
          <el-link style="margin-left: 10px; color: #fff;" icon="el-icon-download" href="/uploads/员工信息.xls" download="" title="员工信息模板">员工信息模板</el-link>
        </el-button> -->
        <el-button type="primary" icon="el-icon-download" @click="handleDownload">下载员工信息模板</el-button>

        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '审核').length" type="success" icon="el-icon-circle-check" @click="check('1')">审核</el-button>
        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '反审核').length" type="success" icon="el-icon-close" @click="check('0')">反审</el-button>

      </el-row>
    </div>
    <br>
    <el-table
      v-loading="listLoading"
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      :data="tableData"
      :header-cell-style="tableHeaderStyle"
      class="table-1"
      max-height="750"
      element-loading-text="正在加载"
      border
      highlight-current-row
      @selection-change="handleSelectionChange"
      @current-change="salaryCurrentChange">
      <el-table-column
        type="selection"
        width="55"/>
      <template v-for="item in formThead">
        <!-- <el-table-column v-if="!item.FRepHide" :width="item.FRepWid" :key="item.FRepIndex" :label="item.FRepCap" align="center"> -->
        <el-table-column v-if="item.frpttypeflag ==0" :key="item.fid" :label="item.frepcap" :width="item.frepwid" align="center" show-overflow-tooltip>
          <!-- <template slot-scope="scope">
            {{ scope.row[item.frepfld] }}
             <template v-else-if="item.frepfld === 'fhiredate'">
              {{ scope.row[item.frepfld] ? scope.row[item.frepfld].split('-').join(''): '' }}
            </template>
          </template>-->

          <template slot-scope="scope">
            <template v-if="item.frephide<=0">
              <template v-if="item.frepfld === 'fstatus'">
                <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                <el-tag v-else size="mini" type="danger">未审</el-tag>
              </template>
              <template v-else size="mini">
                {{ scope.row[item.frepfld] }}
              </template>
            </template>
          </template>

        </el-table-column>
      </template>
    </el-table>

    <el-pagination
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      :total="total"
      :page-sizes="pagesizes"
      :page-size="pagesize"
      :current-page.sync="currentPage"
      class="jy-pagination"
      style="text-align: center; margin-top: 20px;"
      background
      layout="sizes, prev, pager, next, total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"/>

    <el-dialog v-el-drag-dialog :visible.sync="addUserModal" title="添加／编辑" width="70%">
      <hr style="height:1px;margin-top:-33px;border:none;border-top:1px solid #ddd;" >
      <el-form v-loading="loadingForm" ref="form" :rules="rules" :inline="true" :model="form" label-width="150px" class="form1">

        <el-row >
          <el-col v-for="item in dialogThead" :span="12" :key="item.fid ">

            <el-form-item :label="item.frepcap" :prop="item.frepfld" >
              <template v-if="item.frepmeg == 1">
                <template v-if="item.frepfld === 'fcompany'">
                  <el-select v-model="form[item.frepfld]" class="select_el" clearable filterable placeholder="请选择" >
                    <el-option
                      v-for="item2 in gsList"
                      :key="item2.finterid"
                      :label="item2.fname"
                      :value="item2.fname"/>
                  </el-select>
                </template>
                <template v-else>
                  <template v-for="base in baseList" :key="base[item.frepfld] ">
                    <template v-if="base.name === item.frepfld">
                      <el-select v-model="form[item.frepfld]" class="select_el" clearable filterable placeholder="请选择" >
                        <el-option
                          v-for="item2 in base[item.frepfld]"
                          :key="item2.finterid"
                          :label="item2.fname"
                          :value="item2.finterid"/>
                      </el-select>
                    </template>
                  </template>

                </template>

              </template>
              <!-- 日期框-->
              <template v-else-if="item.frepmeg == 4" >
                <template >
                  <el-date-picker v-model="form[item.frepfld]" class="date_el" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" />
                </template>
              </template>

              <!-- 输入框 -->
              <template v-else >
                <el-input v-model="form[item.frepfld]" />
              </template>
            </el-form-item>
          </el-col>
        </el-row>

        <div class="comfirmBtn">
          <el-form-item >
            <el-button :loading="loadingForm" type="primary" @click="confirm" >确认</el-button>
            <el-button @click="addUserModal=false">取消</el-button>
          </el-form-item>
        </div>
      </el-form>
    </el-dialog>

    <!-- 参数配置 -->
    <el-dialog v-el-drag-dialog :visible.sync="configModal" :close-on-click-modal="false" class="config-dialog">
      <head-table
        :config-list="configList"
        :key-value="key"
        @updateConfigData="getUpdateConfigData" />
    </el-dialog>

    <!-- SQL弹窗 -->
    <el-dialog v-el-drag-dialog :visible.sync="dialogSQLModal" :append-to-body="true" title="执行结果">
      <el-form v-loading="loadingFormSQL" ref="formSQL" :rules="rulesSQL" :model="formSQL" label-width="120px">
        <el-form-item label="SQL语句" prop="gzsql">
          <el-input v-model="formSQL.gzsql" :autosize="{ minRows: 14 }" type="textarea"/>
        </el-form-item>
        <el-form-item>
          <el-button :loading="loadingFormSQL" type="primary" @click="confirmSQL" >确认</el-button>
          <el-button @click="dialogSQLModal=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog :visible.sync="tableSetExcel" title="提示：员工信息导出" style="width:30%; margin:auto;">
      <el-button type="primary" @click="downloadFile1()">导出</el-button>
    </el-dialog>

  </div>
</template>
<script>
let FRepKey = ''
const defaultFormThead = []
const defaultOptions = [
  {
    value: 0,
    label: '单据设置'
  },
  {
    value: 1,
    label: '显示SQL语句'
  }
]
import HeadTable from './headTable/index.vue'
import { configColumn, erpZhiyuan, apiZyDel, jichuData, checkStatus } from '../../api/salary'
import { download } from '../../mixins/download.js'
import { common } from '../../mixins/common'
import { company } from '../../mixins/company'
import { pagination } from '../../mixins/pagination'
import { parseTime } from '../../utils/index'
import { tableConfig, apiSql, apiFileSave, downFileUrl } from '../../api/account'
import { genAdd, genDel, genList } from '../../api/gen'

export default {
  name: 'Index',
  components: {
    HeadTable
  },
  filters: {
    parseTime(time, type) {
      return parseTime(time, type)
    }
  },
  mixins: [download, common, company, pagination],
  data() {
    return {
      value: '',
      options: [],
      FRepKey: '',
      keyword: '',
      fdeleted: '',
      fdeletedList: [

      ],
      fdeletedListDiaL: [

      ],
      gapTime: '',
      start_time: '',
      end_time: '',

      // 表头、表格设置
      tableData: [],
      tableList: [],
      defaultFormThead: [],
      formThead: defaultFormThead,
      dialogThead: [],
      curData: {},

      listLoading: false,
      list: [],
      configModal: false,
      configLoading: false,

      loadingForm: false,
      configList: [],
      key: 0,
      // SQL弹窗
      dialogSQLModal: false,
      loadingFormSQL: false,
      formSQL: {
        gzsql: ''
      },
      rulesSQL: {

      },

      form: {},
      rules: {
        fnumber: [
          { required: true, message: '请输入职员编号', trigger: 'blur' }
        ],
        fname: [
          { required: true, message: '请选择职员姓名', trigger: 'blur' }
        ]
      },
      addUserModal: false,
      // loadingForm: false

      fileList: [],

      // 批量删除
      checkData: [],
      selectedData: [],

      // 用户菜单
      menusList: [],
      limits: [],
      userKey: '',

      // // 下拉列表
      // gsList: [ // 公司名称
      //   {
      //     finterid: 0,
      //     fname: 'PCTX'
      //   },
      //   {
      //     finterid: 1,
      //     fname: 'SQ'
      //   }
      // ],
      bmwzList: [ // 部门位置
        {
          finterid: 0,
          fname: '钢壳'
        },
        {
          finterid: 1,
          fname: '铝壳'
        },
        {
          finterid: 2,
          fname: '14500'
        }
      ],

      upData: {},
      fdeptname: '', // 部门
      bmList: [], // 部门
      xlList: [], // 学历
      zwList: [], // 职务
      xbList: [], // 性别
      lzztList: [],

      baseList: [],

      filename: '',
      bookType: 'xlsx',

      detail: '',
      detailVisible: false,

      tableSetExcel: false,
      url: ''
    }
  },
  async mounted() {
    this.userKey = this.$route.meta.FRepKey
    FRepKey = this.$route.meta.FRepKey
    this.upData.db = this.globalDb.db
    this.upData.FRepKey = this.$route.meta.FRepKey
    this.options = defaultOptions
    await this.getAllData()
    await this.getjichuData()
  },
  methods: {
    async toDetail(data) {
      this.detailVisible = true
      this.detail = data
    },
    async getjichuData() {
      try {
        const res = await jichuData({
          opername: decodeURIComponent(this.globalDb.fname),
          db: this.globalDb.db
        })

        this.baseList.push({ name: 'fdepid', 'fdepid': res.Data.fdepid }, { name: 'fgender', 'fgender': res.Data.fgender }
          , { name: 'fduty', 'fduty': res.Data.fduty }, { name: 'fdegree', 'fdegree': res.Data.fdegree }, { name: 'fdeleted', 'fdeleted': res.Data.fdeletedid })

        this.bmList = res.Data.fdepid
        this.xbList = res.Data.fgender
        this.zwList = res.Data.fduty
        this.xlList = res.Data.fdegree
        this.lzztList = res.Data.fdeletedid
        this.fdeletedList = this.lzztList.map((item, index) => {
          return { value: index + 1, label: item.fname }
        })
        this.fdeletedList.unshift({ value: 0, label: '全部' })
      } catch (error) {
        console.log(error)
      }
    },
    selectFBirthday(val) {
      this.form.fbirthday = parseTime(val, '{y}-{m}-{d}')
    },
    selectFHireDate(val) {
      this.form.fhiredate = parseTime(val, '{y}-{m}-{d}')
    },
    selectFLeaveDate(val) {
      this.form.fleavedate = parseTime(val, '{y}-{m}-{d}')
    },
    // -----------------上传开始---------------------
    beforeAvatarUpload(file) {
      var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
      const extension = testmsg === 'xls' || testmsg === 'xlsx'
      const isLt2M = file.size / 1024 / 1024 < 1
      if (!extension) {
        this.$message({
          message: '上传文件只能是 xls/xlsx格式!',
          type: 'warning'
        })
      }
      if (!isLt2M) {
        this.$message({
          message: '上传文件大小不能超过 1MB!',
          type: 'warning'
        })
      }

      const fd = new FormData()
      fd.append('file', file)

      // console.log(fd)

      if (extension) {
        return true
      } else {
        this.$message.warning('只能上传excel文件格式xls/xlsx')
        return false
      }
      // return extension  && isLt2M
    },
    // computed: {
    // // 这里定义上传文件时携带的参数，即表单数据
    //   upData: function() {
    //     return {
    //       db: this.globalDb.db
    //     }
    //   }
    // },
    async submitUpload() {
      this.$refs.upload.submit()
    },

    handleRemove(file, fileList) {
      // console.log(file, fileList)
    },
    handlePreview(file) {
      // console.log(file)
    },
    exceed() {
      // 重复选择文件,弹出错误弹窗
      this.$message('最多仅支持上传一个文件')
    },
    notice(e) {
      if (e.Error === 0) {
        this.$message(e.Message)
        this.getAllData()
        console.log(222222222)
        this.$refs.upload.clearFiles()
      } else {
        this.$message(e.Message)
      }
    },
    // -----------------上传结束---------------------
    // 获取所有员工信息 erp职员列表(需要导出的数据)
    async getExportData(total) {
      if (!total) return
      try {
        const res = await erpZhiyuan({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          keyword: this.keyword,
          fdeleted: this.fdeleted ? this.fdeleted : '0',
          fdeptname: this.fdeptname, // 部门名称
          fcompany: this.fcompany,
          // start_time: this.start_time,
          // end_time: this.end_time,
          limit: total,
          page: this.currentPage
        })
        this.listData = res.result
        this.formThead.map(item => {
          this.listData.map(it => {
            if (item.FRepType === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.FDecPlaces)
            }
          })
        })
      } catch (error) {
        // console.log(error)
      }
    },
    // 导出数据
    async downData() {
      this.exportData(FRepKey)
    },
    async getAllData() {
      await this.getBodyData()
      await this.getHeadData()
      // 菜单列表（权限）
      const menuRes = JSON.parse(localStorage.getItem('setMenuData'))
      // console.log(menuRes, ' menuRes')
      this.menusList = menuRes
      if (menuRes.length >= 1) {
        menuRes.map(it => {
          it.children.map(item => {
            if (item.fobjectid === this.userKey) {
              this.$set(this, 'limits', item.child)
            }
          })
        })
        // console.log(this.limits, '  this.limits')
      }
    },

    selectSettings(val) {
      // console.log(val, ' val SQL')
      if (val === 0) {
        this.settings()
      } else if (val === 1) {
        this.dialogSQL()
      }
    },
    settings() {
      this.configModal = true
      this.getTableConfig()
    },

    // 更新数据
    async getUpdateConfigData() {
      await this.getTableConfig()
      await this.getBodyData()
      await this.getHeadData()
    },

    // SQL修改/更新
    async dialogSQL() {
      this.dialogSQLModal = true
      try {
        const res = await apiSql({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          FRepKey
        })
        // console.log(res, ' res')
        if (res.Error === 0) {
          this.formSQL.gzsql = res.Data
          this.formSQL.FRepKey = FRepKey
        }
        setTimeout(() => {
          this.$refs['formSQL'].clearValidate()
        })
      } catch (error) {
        // console.log(error)
      }
    },

    confirmSQL() {
      this.$refs['formSQL'].validate(async(valid) => {
        if (valid) {
          try {
            this.formSQL.db = this.globalDb.db
            this.formSQL.opername = decodeURIComponent(this.globalDb.fname)
            const res = await apiFileSave(this.formSQL)
            if (res.Error === 0) {
              this.dialogSQLModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })
            } else {
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },

    async getTableConfig() {
      try {
        this.configLoading = true
        const res = await tableConfig({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          key: FRepKey
        })
        this.configList = res.Data
        this.key = FRepKey
        this.configLoading = false
      } catch (error) {
        this.configLoading = false
      }
    },

    // 表头数据
    async getHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        // this.tableList = []
        this.formThead.map(item => {
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.tableData = this.tableList.slice()

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.tableList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fitemid') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      //  console.log(this.dialogThead, '  this.dialogThead')
      } catch (error) {
        this.listLoading = false
        // console.log(error)
      }
    },

    // 表体数据————erp职员列表
    async getBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          keyword: this.keyword,
          fdeleted: this.fdeleted ? this.fdeleted : '0', // 1-在职，2-离职 ，0-全部
          fdeptname: this.fdeptname, // 部门名称
          fcompany: this.fcompany,
          start_time: this.start_time,
          end_time: this.end_time,
          limit: this.pagesize,
          page: this.currentPage,
          FRepKey
        })
        this.listLoading = false
        // console.log(res, ' 123res.result')
        this.tableList = res.Data
        this.total = res.total
      //  await this.getExportData(this.total)
      } catch (error) {
        this.listLoading = false
        console.log(error)
      }
    },
    selectGapTime(val) {
      if (val) {
        this.start_time = parseTime(val[0], '{y}-{m}-{d}')
        this.end_time = parseTime(val[1], '{y}-{m}-{d}')
      } else {
        this.start_time = ''
        this.end_time = ''
      }
      this.searchUser()
    },
    async searchUser() {
      // await this.getBodyData()
      // await this.getHeadData()
      await this.getAllData()
    },
    async handleSizeChange(val) {
      this.currentPage = 1
      this.pagesize = val
      // await this.getBodyData()
      // await this.getHeadData()
      await this.getAllData()
    },
    async handleCurrentChange(val) {
      this.currentPage = val
      // await this.getBodyData()
      // await this.getHeadData()
      await this.getAllData()
    },
    salaryCurrentChange(val) {
      this.curData = val
    },
    // 添加
    async addUser() {
      this.bmList = [] // 部门
      this.xlList = [] // 学历
      this.zwList = [] // 职务
      this.xbList = [] // 性别
      this.lzztList = []
      this.baseList = []

      await this.getjichuData()

      this.form = {}
      const data = {}
      // console.log(this.formThead, '  this.formThead')
      this.dialogThead.map(item => { data[item.frepfld] = '' })
      for (const i in data) {
        this.$set(this.form, i, data[i])
      }
      // console.log(this.form, ' addUser this.form')
      this.lzztList.map(item => {
        // '在职'
        if (item.fname === '在职') {
          this.form.fdeleted = item.finterid
        }
      })
      // console.log('add', this.form.fdeleted)
      setTimeout(() => {
        this.$refs['form'].clearValidate()
      })

      this.addUserModal = true
    },

    // 修改
    async editUser() {
      this.bmList = [] // 部门
      this.xlList = [] // 学历
      this.zwList = [] // 职务
      this.xbList = [] // 性别
      this.lzztList = []
      this.baseList = []

      await this.getjichuData()

      this.form = {}
      console.log(this.selectedData, '  this.selectedData')
      if (this.selectedData.length !== 1) {
        this.$message({
          message: '请选中要编辑的一行',
          type: 'warning'
        })
        return
      }
      // const data = this.curData
      const data = this.selectedData[0]
      console.log(data, ' data edit')
      this.dialogThead.map(item => { this.$set(this.form, item.frepfld, '') })
      this.form.fitemid = ''

      // console.log(this.dialogThead, ' this.form edit')
      this.addUserModal = true
      for (const i in this.form) {
        this.form[i] = data[i]
        this.dialogThead.map(item => {
          if (item.frepmeg === 1 && i === item.frepfld && !data[i]) {
            this.form[i] = ''
          }
        })
      }
      setTimeout(() => {
        this.$refs['form'].clearValidate()
      })
    },

    async confirm() {
      this.$refs['form'].validate(async(valid) => {
        if (valid) {
          this.loadingForm = true
          try {
            console.log(this.form, ' confirm this.form')
            this.form.db = this.globalDb.db
            this.form.FRepKey = FRepKey
            this.form.opername = decodeURIComponent(this.globalDb.fname)
            const res = await genAdd(this.form)
            if (res.Error === 0) {
              this.loadingForm = false
              this.addUserModal = false
              // console.log(res, ' res add')
              this.$message({
                message: res.Message,
                type: 'success'
              })
              // await this.getBodyData()
              // await this.getHeadData()
              await this.getAllData()
            } else {
              this.loadingForm = false
              // this.addUserModal = false
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            this.loadingForm = false
            console.log(error)
          }
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },

    async delUser() {
      const data = this.checkData

      const dataTemp = this.selectedData
      const isFstatus = dataTemp.filter(it => Number(it.fstatus) === 1)

      if (isFstatus.length) {
        this.$message({
          message: '已审核，不能删除！',
          type: 'warning'
        })
        return
      }
      if (!data) {
        this.$message({
          message: '请选中要删除的一行',
          type: 'warning'
        })
        return
      }

      this.$confirm('此操作将永久删除,可能导致其他模块引用该员工记录为空， 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'btn-custom-cancel',
        type: 'warning'
      }).then(async() => {
        console.log(data, ' data')
        const fitemid = data.join(',')
        const res = await genDel({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          fid: fitemid,
          FRepKey

        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          // await this.getBodyData()
          // await this.getHeadData()
          await this.getAllData()
          return
        }
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    async check(Fstatus) {
      // if (!this.appUser) {
      //   this.$message({
      //     message: '请选择员工',
      //     type: 'error'
      //   })
      //   return
      // }
      if (!this.checkData.length) {
        this.$message({
          message: '请选择表格行数据',
          type: 'error'
        })
        return
      }
      if (Number(Fstatus) === 1) {
        this.$confirm('是否审核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          cancelButtonClass: 'btn-custom-cancel',
          type: 'warning'
        }).then(async() => {
          try {
            const res = await checkStatus({
              db: this.globalDb.db,
              opername: decodeURIComponent(this.globalDb.fname),
              loginname: decodeURIComponent(this.globalDb.fname),
              FRepKey,
              Fstatus, // 1—审核，0—反审
              fid: this.checkData.join(','),
              appname: ''
            })
            if (res.Error === 0) {
              this.$message({
                message: res.Message,
                type: 'success'
              })
              await this.getAllData()
            } else {
              this.loadingForm = false
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      } else {
        try {
          const res = await checkStatus({
            db: this.globalDb.db,
            opername: decodeURIComponent(this.globalDb.fname),
            loginname: decodeURIComponent(this.globalDb.fname),
            FRepKey,
            Fstatus, // 1—审核，0—反审
            fid: this.checkData.join(','),
            appname: ''
          })
          if (res.Error === 0) {
            this.$message({
              message: res.Message,
              type: 'success'
            })
            await this.getAllData()
          } else {
            this.loadingForm = false
            this.$message({
              message: res.Message,
              type: 'error'
            })
          }
        } catch (error) {
          console.log(error)
        }
      }
    },

    // 下载
    async handleDownload() {
      const res = await downFileUrl({
        db: this.globalDb.db,
        opername: decodeURIComponent(this.globalDb.fname),
        FRepKey
      })
      if (res.Error === 0) {
        this.tableSetExcel = true
        this.url = res.Data
      } else {
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }
    },

    downloadFile1() {
      this.tableSetExcel = false
      // window.open('/api/download?d=' + this.url)
      window.open('/api/downloadFile?FRepKey=' + FRepKey)
    },

    handleSelectionChange(val) {
      this.checkData = []
      this.selectedData = val
      console.log(val, ' val 选择框')
      val.map(it => {
        this.checkData.push(it.fitemid)
      })
      console.log(this.checkData, "  this.checkData.join(', ')")
      // this.checkData = val
    },
    async delPlUser() {
      console.log(this.checkData, '  this.checkData')
      if (!this.checkData.length) {
        this.$message({
          message: '请选中要删除的行',
          type: 'warning'
        })
        return
      }

      this.$confirm('此操作将批量删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'btn-custom-cancel',
        type: 'warning'
      }).then(async() => {
        const fitemid = this.checkData.join(',')
        const res = await apiZyDel({
          db: this.globalDb.db,
          opername: decodeURIComponent(this.globalDb.fname),
          // FRepKey: this.userKey,
          fitemid
        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          // await this.getBodyData()
          // await this.getHeadData()
          await this.getAllData()
          return
        }
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }

  }
}

</script>
<style lang="scss" scoped>
.config-dialog ::v-deep .el-dialog {
  width: 90%;
}
  .el-rowdiv, button, .upload-demo {
    margin-top: 10px;
  }
  .detail-footer {
    position: relative;
    bottom: 30px;
    // overflow: hidden;
    // display: inline-block;
    // el-button {
    //   float: right;
    // }
  }
  .scrollbar {
    /deep/ .el-scrollbar__wrap {  // 必要的
      overflow: scroll;
      // width: 110%;  //隐藏侧边默认滚动条 （达不到效果可以自己试着微调） 如解决不了可尝试用 `margin-right -60px`
      height: 110%;  //隐藏底部滚动条  （100%如果达不到效果可以试着用110%）
      padding-bottom: 40px;
    }
  }

.form1  .select_el{
     width:92%;
     //border:1px solid blue
  }

  .form1  .date_el{
     width:86%;
     //border:1px solid red
  }
   .form1  .comfirmBtn{
     margin-top:20vm;
     text-align: center;
  }
  .el-dialog__wrapper {
   // width:90%;
  }

</style>
